﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MagicArena.framework.state;
using MagicArena.framework.toon;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using MagicArena.framework.graphics._2d;

namespace MagicArena.framework.graphics
{
    public class RendererSprite : ARenderer
    {
        #region Constant vals
        // The default state for properties
        public const float XPOS = 0, YPOS = 0, WIDTH = 10, HEIGHT = 10;
        #endregion

        #region Properties
        public State Xpos
        {
            get;
            private set;
        }
        public State Ypos
        {
            get;
            private set;
        }
        public State Width
        {
            get;
            private set;
        }
        public State Height
        {
            get;
            private set;
        }
        protected string ToonName
        {
            get;
            private set;
        }
        public Texture2D Texture
        {
            get;
            private set;
        }
        public Rectangle Rect
        {
            get
            {
                return new Rectangle((int)Xpos.Value, (int)Ypos.Value, (int)Width.Value, (int)Height.Value);
            }
        }
        #endregion

        public RendererSprite() : base()
        {
            
        }

        ~RendererSprite() // Destructor
        {
            Render2dSingleton.Instance.Remove(this);
        }

        public override void AttachToToon(Toon t)
        {
            base.AttachToToon(t);
            Xpos = State.FindState(t.States, State.Common.Xpos, XPOS);
            Ypos = State.FindState(t.States, State.Common.Ypos, YPOS);
            Width = State.FindState(t.States, State.Common.Width, WIDTH);
            Height = State.FindState(t.States, State.Common.Height, HEIGHT);

            ToonName = t.Name;

            Texture = TexToRender(ToonName);

            Render2dSingleton.Instance.Add(this);
        }

        protected override void Render()
        {
            //TODO Check for any state changes, change the texture to display accordingly
        }

        #region Private helper methods
        
        private Texture2D TexToRender(string name)
        {
            return null;
        }
        #endregion

        public override void Update(GameTime gameTime)
        {
            //TODO Change texture based on time, aka animation
        }
    }
}
